<template>
	<view class="contain">
		<view class="tip">
			若你忘记了密码，可在此重置新密码
		</view>
		<view class="input_c">
			<input type="text" :value="mobileNum" placeholder="请输入手机号码" />
		</view>
		<view class="password_c input_c">
			<input :type="passwordShowStatus.seen ? 'password' : 'text'" @input="pwdInput" :value="passwordNum" placeholder="请输入新密码" />
			<view class="show_img" @tap="changeShowPassword">
				<image v-if="!passwordShowStatus.seen" src="../../../static/image/xianshi.png" mode="scaleToFill"></image>
				<image v-else src="../../../static/image/yincang.png" mode="scaleToFill"></image>
			</view>
		</view>
		<view class="auth_code input_c">
			<input type="number" :value="authCode" placeholder="验证码" />
			<view class="get_auth_code" @tap="noFn">
				获取重置码
			</view>
		</view>
		<view class="sub">
			重置密码
		</view>
	</view>
</template>

<script>
	import WxValidate from "../../../utils/WxValidate.js";

	export default {
		data() {
			return {
				user: {
					mobileNum: '',
					passwordNum: undefined

				},
				passwordShowStatus: {
					seen: false,

				},
				authCode: '',
			};
		},
		methods: {
			changeShowPassword() {
				this.passwordShowStatus.seen = !this.passwordShowStatus.seen;
			},
			// 功能未开发
			noFn() {
				uni.showToast({
					title: '功能未开发, 无需输入',
					icon: "none"
				})
			},

			async sub() {
				const error = (() => {
					let params = this.newUserInfo;
					if (!this.WxValidate.checkForm(params)) {
						//表单元素验证不通过，此处给出相应提示
						let error = this.WxValidate.errorList[0];
						console.log(params);
						switch (error.param) {
							case "mobileNum":
							case "password":
								uni.showToast({
									title: error.msg,
									icon: "none"
								})
								break;
						}
						return true;
					} else {
						return false
					}
				})()
				// 当没有错误时
				if (!error) {
					const res = await request({
						url: "/member/register",
						method: "POST",
						data: {

							"birthday": "",
							"city": "",
							"createTime": "",
							"email": "",
							"growth": 0,
							"historyIntegration": 0,
							"icon": "/static/icons/leju-logo.png",
							"integration": 0,
							"isDisabled": 0,
							"memberLevelId": "",
							"nickname": this.newUserInfo.userNickname,
							"password": this.newUserInfo.password,
							"personalizedSignature": "",
							"phone": this.newUserInfo.mobileNum,
							"realname": "",
							"sex": 0,
							"sourceType": 0,
							"status": 1,
							"username": this.newUserInfo.userName,
							"wxOpenId": ""

						}
					});
					if (res.data.success == true) {
						uni.showToast({
							title: '注册成功,1秒后跳转至登录页面'
						});
						setTimeout(() => {
							uni.navigateTo({
								url: '../login'
							})
						}, 1500)
					} else {
						uni.showToast({
							title: res.data.message,
							icon: "none"
						})
					}
				}
			},
			initValidate() {
				let rules = {
					mobileNum: {
						required: true,
						tel: true
					},
					password: {
						required: true,
					}
				}

				let message = {
					mobileNum: {
						required: '请输入手机号',
						tel: '请输入正确的手机号'
					},
					password: {
						required: "未输入新密码",
					}

				}
				//实例化当前的验证规则和提示消息
				this.WxValidate = new WxValidate(rules, message);
			},
			// 密码框同步数据
			pwdInput(e) {
				this.newUserInfo.password = e.detail.value;
			},
		},
		onLoad() {
			this.initValidate();
		}
	}
</script>

<style lang="scss" scoped>
	@import "./resetPassword.scss";
</style>
